package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysRoleMenuService;
import com.seahorse.youliao.service.entity.SysRoleMenuDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysRoleMenuQueryVO;
import com.seahorse.youliao.vo.response.SysRoleMenuPageInfoVO;
import com.seahorse.youliao.vo.response.SysRoleMenuResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 角色和菜单关联表
* @author : songqiang
* @date: 2020-01-17 09:23:45.934
**/
@RestController
@Api("SysRoleMenuController")
@RequestMapping("sysRoleMenu")
@Validated
public class SysRoleMenuController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysRoleMenuController.class);
    
	@Autowired
    private SysRoleMenuService sysRoleMenuService;
    /**
     * 分页查询
     * @param sysRoleMenuQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysRoleMenuPageInfoVO selectPageList(@RequestBody @Valid SysRoleMenuQueryVO sysRoleMenuQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysRoleMenuQueryVO.toString());
        LOGGER.info(info);
        SysRoleMenuDTO sysRoleMenu = BeanUtil.convert(sysRoleMenuQueryVO, SysRoleMenuDTO.class);

        Page<SysRoleMenuResponseVO> page = PageHelper.startPage(sysRoleMenuQueryVO.getPageNum(), sysRoleMenuQueryVO.getPageSize());
        List<SysRoleMenuDTO> sysRoleMenuList = sysRoleMenuService.getList(sysRoleMenu);
        SysRoleMenuPageInfoVO sysRoleMenuPageInfo = new SysRoleMenuPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysRoleMenuPageInfo);
        List<SysRoleMenuResponseVO> voList = BeanUtil.convert(sysRoleMenuList, SysRoleMenuResponseVO.class);
        sysRoleMenuPageInfo.setList(voList);

        return sysRoleMenuPageInfo;
    }


}
